<?php
Globals::requireClass('Controller');
Globals::requireModel('User');
Globals::requireTable('Recommend');

class RecommendController extends Controller
{
    protected $RecommendTable;
	
	public static $defaultConfig = array(
		'viewEnabled'	=> true,
		'layoutEnabled'	=> true,
		'title'			=> null
	);
	
	public function __construct($config = null)
	{
	    parent::__construct($config);
	    $this->RecommendTable = new RecommendTable($config);
		dolog(json_encode($_GET));
	}
	
	public function indexAction()
	{
		$this->layout->pageTitle	= "test";
	}
	
	
	public function moreAction(){
	    $uid = $this->getParam('uid');
	    $token = $this->getParam('token');
	    $machine_type = $this->getParam('machine_type');
	    $usermodel = new UserModel($this->config);
	    $uid = $usermodel->getUserBase($uid, $token ,$machine_type);
	    if($uid < 1){
	        echo json_encode(array('returncode'=>'-1','message'=>'','moretime'=>'','data'=>array()));
	        exit();
	    }
	    
	    $moretime = $this->getParam('moretime');
	    $data = array();
	    
	    $lasttime = $this->RecommendTable->getRowWithFields('createdate','','createdate desc');
	    if($lasttime['createdate'] > $moretime){
	        $moretime = $lasttime['createdate'];
	        
	        $redata = $this->RecommendTable->listAll('','id asc');
	        foreach ($redata as $v){
	            $data[] = array('title'=>$v['title'],'url'=>$v['url']);
	        }
	    }
	    
	    echo json_encode(array('returncode'=>'0','message'=>'成功','moretime'=>$moretime,'data'=>$data));
	    exit();
	}
	
	protected function out()
	{
		$this->layout->nav		= 'index';
		parent::out();
	}
}

Config::extend('RecommendController', 'Controller');
